package org.mx.notify.error;

import org.mx.error.UserInterfaceError;
import org.mx.error.UserInterfaceException;
import org.mx.spring.utils.I18nMessageUtils;

/**
 * 描述： WebSocket消息推送错误枚举定义
 *
 * @author john peng Date time 2021/2/26
 */
public class UserInterfaceWsNotifyErrorException extends UserInterfaceException {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6531644242279224047L;

	/**
	 * 默认的构造函数
	 */
	public UserInterfaceWsNotifyErrorException() {
		this(WsNotifyErrors.WS_NOTIFY_OTHER_FAIL);
	}

	/**
	 * 构造函数
	 *
	 * @param error 人机界面错误枚举
	 */
	public UserInterfaceWsNotifyErrorException(WsNotifyErrors error) {
		super(error.getErrorCode(), error.getErrorMessage());
	}

	/**
	 * JWT（JSON Web Tokens）操作错误枚举定义
	 */
	@SuppressWarnings("javadoc")
	public enum WsNotifyErrors implements UserInterfaceError {
		MESSAGE_BLANK("消息内容为空。"),

		JSON_PATH_BLANK("JSON路径为空。"), 
		JSON_PATH_PATH_NOT_FOUND("指定的JSON路径不存在。"),

		WS_NOTIFY_OTHER_FAIL("未知JWT(JSON Web Tokens)错误。");

		public static final int BASE_ORDINAL = 180;
		private String errorMessage;

		/**
		 * 构造函数
		 *
		 * @param errorMessage 错误信息
		 */
		WsNotifyErrors(String errorMessage) {
			this.errorMessage = errorMessage;
		}

		/**
		 * {@inheritDoc}
		 *
		 * @see UserInterfaceError#getErrorCode()
		 */
		@Override
		public int getErrorCode() {
			return BASE_ORDINAL + super.ordinal();
		}

		/**
		 * {@inheritDoc}
		 *
		 * @see UserInterfaceError#getErrorMessage()
		 */
		@Override
		public String getErrorMessage() {
			return I18nMessageUtils.getI18nMessage(super.name(), this.errorMessage);
		}
	}
}
